<?php
namespace Index\Controller;
use Think\Controller;
class UserController extends Controller {
    public function index(){

        $userId = session("uinfo")["id"];
        $model = M("userinfo");
        $userInfo = $model->find($userinfo);
        $this->assign("userInfo",$userInfo);
    	$this->assign("selectIndex",0);
    	$this->display();
    }

    public function edit(){
        $userId = session("uinfo")["id"];
         
        if ($_SERVER['REQUEST_METHOD'] == "POST") {
             $model = M("userinfo");
             $data["name"] = I("post.userName");
             $data["sex"] = I("post.sex");
             $data["introduction"] = I("post.userInstro");
             $data["constell"] = I("post.constell");
             $data["city"] = I("post.city");

            if ($_FILES["file"]["name"]) {
                $upload = new \Think\Upload();// 实例化上传类
                $upload->maxSize   =     3145728 ;// 设置附件上传大小
                $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
                $upload->rootPath  =     'Public/uploads/'; // 设置附件上传根目录
                $upload->savePath  =     ''; // 设置附件上传（子）目录
                // 上传文件 
                $info   =   $upload->upload();
                if(!$info) {// 上传错误提示错误信息
                 //echo $upload->getError();
                }else{// 上传成功
                    foreach($info as $file){
                        $fileUrl = "uploads/".$file['savepath'].$file['savename'];
                        $data["head_pic"] = $fileUrl;
                }
            }
            }
             $model->where("id=".$userId)->save($data);
        }

        $model = M("userinfo");
        $userInfo = $model->find($userinfo);
        $this->assign("userInfo",$userInfo);
    	$this->assign("selectIndex",1);
    	$this->display();
    }

    public function mycollect(){
        $userId = session("uinfo")["id"];
        $model = M("userinfo");
        $userInfo = $model->find($userinfo);
        $this->assign("userInfo",$userInfo);
    	$this->assign("selectIndex",2);
    	$this->display();
    }


   






}